package com.yb.forum.controller;

import com.yb.forum.common.AppResult;
import com.yb.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
 public class TestController {
    @ApiOperation("测试接口1,hello forum")
    @GetMapping("/hello")
    public String hello(){
        return "hello forum";
    }
    @ApiOperation("测试接口2,显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException()throws Exception{
        throw new Exception("这是一个Exception...");
    }
    @ApiOperation("测试接口3,显示显示自定义的异常信息")
    @GetMapping("/appException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationException...");
    }

    /**
     *
     * @param name 在name参数前面需要加上@RequestParam注解,是SpringMvc的注解
     * @return
     */
    @PostMapping("/helloByName")
    @ApiOperation("测试接口4,按传入的姓名显示你好信息")
    public AppResult helloByName(@ApiParam("要传入的姓名") @RequestParam("name") String name){
        return AppResult.success(name);
    }
}
